package com.jike.noobmoney.helper;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.jike.noobmoney.R;

/**
 * Created by Think on 2017/11/1.
 * <></>
 */

public class ImageLoader {

    @SuppressLint("CheckResult")
    public static RequestOptions getRequestOptions(int placeholder, int error) {
        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .dontAnimate()
                .placeholder(placeholder)
                .error(error);
        return options;
    }

    @SuppressLint("CheckResult")
    public static RequestOptions getCircleRequestOptions(int placeholder, int error) {
        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .dontAnimate()
                .placeholder(placeholder)
                .error(error)
                .transform(new GlideCircleTransform());
        return options;
    }


    public static void displayImageBanner(Context context, String path, ImageView imageView) {
        Glide.with(context).setDefaultRequestOptions(getRequestOptions(R.drawable.ic_default_banner, R.drawable.ic_default_banner)).load(path)
                .into(imageView);
    }

    public static void displayImage(Context context, int path, final ImageView imageView) {
        Glide.with(context).load(path)
                .into(imageView);
    }

    public static void displayImageDefaultActive(Context context, String path, final ImageView imageView) {
        Glide.with(context).setDefaultRequestOptions(getRequestOptions(R.drawable.ic_default_active, R.drawable.ic_default_active)).load(path)
                .into(imageView);
    }

    public static void displayImageDefaultLogo(Context context, String path, final ImageView imageView) {
        Glide.with(context).setDefaultRequestOptions(getRequestOptions(R.drawable.ic_default_icon, R.drawable.ic_default_icon)).load(path)
                .into(imageView);
    }

    public static void displayImageDefaultLogo(Context context, int path, final ImageView imageView) {
        Glide.with(context).setDefaultRequestOptions(getRequestOptions(R.drawable.ic_default_icon, R.drawable.ic_default_icon)).load(path)
                .into(imageView);
    }

    public static void displayImageDefaultCircle(Context context, String path, final ImageView imageView) {
        Glide.with(context).setDefaultRequestOptions(getCircleRequestOptions(R.drawable.ic_default_circle, R.drawable.ic_default_circle))
                .load(path)
                .into(imageView);
    }

    public static void displayImageDefaultCircle(Context context, int path, final ImageView imageView) {
        Glide.with(context).setDefaultRequestOptions(getCircleRequestOptions(R.drawable.ic_default_circle, R.drawable.ic_default_circle))
                .load(path)
                .into(imageView);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public static void displayImage(Activity activity, String path, final ImageView imageView) {
        if (activity != null && !activity.isDestroyed()) {
            Glide.with(activity).load(path).into(imageView);
        }
    }

    public static void displayImage(Context context, String path, final ImageView imageView) {
        Glide.with(context).load(path)
                .into(imageView);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public static void displayImageDefaultHead(Activity activity, String path, final ImageView imageView) {
        if (activity != null && !activity.isDestroyed()) {
            Glide.with(activity).setDefaultRequestOptions(getCircleRequestOptions(R.drawable.ic_user_default, R.drawable.ic_user_default)).load(path)
                    .into(imageView);
        }
    }

    public static void displayImageDefaultHead(Context context, String path, final ImageView imageView) {
        if (context != null) {
            Glide.with(context).setDefaultRequestOptions(getCircleRequestOptions(R.drawable.ic_user_default, R.drawable.ic_user_default)).load(path)
                    .into(imageView);
        }
    }

    public static void displayImageDefaultHead(Context context, int path, final ImageView imageView) {
        if (context != null) {
            Glide.with(context).setDefaultRequestOptions(getCircleRequestOptions(R.drawable.ic_user_default, R.drawable.ic_user_default)).load(path)
                    .into(imageView);
        }
    }

}
